//
//  HWGameOpenServiceTableController.swift
//  HWanGame
//
//  Created by 王昌健 on 2022/3/9.
//  Copyright © 2022 94Wan. All rights reserved.
//

import UIKit
import JXSegmentedView
class HWGameOpenServiceTableController: HWBaseViewController {
    var segmentedView: JXSegmentedView = JXSegmentedView(frame: CGRect.zero)
    var segmentedDataSource: JXSegmentedTitleDataSource!
    var listContainerView: JXSegmentedListContainerView!
    override func viewDidLoad() {
        super.viewDidLoad()

        initUI()
        
        initFrame()
        
    }

}

extension HWGameOpenServiceTableController {
    private func initUI() -> Void {
        navigationView.isHidden = true
        
        segmentedDataSource = JXSegmentedTitleDataSource()
        segmentedDataSource.titles = ["即将开服","已经开服"]
        segmentedDataSource.isTitleColorGradientEnabled = true
        segmentedDataSource.titleNormalColor = UIColor.colorWithHexString(hexString: "#444444")
        segmentedDataSource.titleSelectedColor = UIColor.colorWithHexString(hexString: "#F87706")
        segmentedDataSource.titleNormalFont = .systemFont(ofSize: 14*widthScale)
        segmentedDataSource.titleSelectedFont = .boldSystemFont(ofSize: 14*widthScale)
        segmentedView.dataSource = segmentedDataSource
        
        let indicator = JXSegmentedIndicatorLineView()
        indicator.indicatorColor = .colorWithHexString(hexString: "#F87706")
//        indicator.indicatorHeight = 4*widthScale
//        indicator.indicatorWidth = 36*widthScale
//        indicator.contentMode = .scaleAspectFill
        indicator.indicatorCornerRadius = 2
        indicator.layer.masksToBounds = true
        indicator.verticalOffset = 3*widthScale
        segmentedView.indicators = [indicator]
        segmentedView.delegate = self
        segmentedView.backgroundColor = .clear
        view.addSubview(self.segmentedView)
        
        
        listContainerView = JXSegmentedListContainerView(dataSource: self)
        view.addSubview(listContainerView)
        
        segmentedView.listContainer = listContainerView
        segmentedView.backgroundColor = .white
    }
    
    private func initFrame() -> Void {
        segmentedView.snp.makeConstraints { make in
            make.top.equalToSuperview()
            make.left.right.equalToSuperview()
            make.height.equalTo(35*widthScale)
        }
        
        listContainerView.snp.makeConstraints { make in
            make.top.equalTo(segmentedView.snp.bottom)
            make.left.right.bottom.equalToSuperview()
        }
    }
}
extension HWGameOpenServiceTableController:JXSegmentedListContainerViewListDelegate {
    func listView() -> UIView {
        return view
    }
}
extension HWGameOpenServiceTableController:JXSegmentedListContainerViewDataSource,JXSegmentedViewDelegate {
    func numberOfLists(in listContainerView: JXSegmentedListContainerView) -> Int {
        return segmentedDataSource.dataSource.count
    }
    
    func listContainerView(_ listContainerView: JXSegmentedListContainerView, initListAt index: Int) -> JXSegmentedListContainerViewListDelegate {
        let openService = HWGameOpenServiceListController()
        if index == 0 {
            openService.type = "0"
        }else {
            openService.type = "1"
        }
        return openService
    }
    
    func segmentedView(_ segmentedView: JXSegmentedView, didSelectedItemAt index: Int) {
        
    }
}
